package ACM_Brush;

import java.util.Scanner;

public class Solution148 {
    public static void main(String[] args) {
        ListNode head = new ListNode();
        ListNode dummyNode = head;
        try (Scanner in = new Scanner(System.in)) {
            int num = in.nextInt();
            while (num-- != 0) {
                ListNode node = new ListNode(in.nextInt());
                dummyNode.next = node;
                dummyNode = dummyNode.next;
            }
        }
        ListNode result = new solution_148().sortList(head.next);
        while (result != null) {
            System.out.printf("%d->", result.val);
            result = result.next;
        }
    }
}

class solution_148 {
    public ListNode sortList(ListNode head) {
        if (head == null || head.next == null)
            return head;
        ListNode slow = head, fast = head, node = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        while (node.next != slow)
            node = node.next;
        node.next = null;

        ListNode sortedLeft = sortList(head);
        ListNode sortedRight = sortList(slow);

        return merge(sortedLeft, sortedRight);
    }

    private ListNode merge(ListNode sortedLeft, ListNode sortedRight) {
        ListNode result = new ListNode();
        ListNode dummyNode = result;
        while (sortedLeft != null && sortedRight != null) {
            if (sortedLeft.val < sortedRight.val) {
                dummyNode.next = sortedLeft;
                sortedLeft = sortedLeft.next;
            } else {
                dummyNode.next = sortedRight;
                sortedRight = sortedRight.next;
            }
            dummyNode = dummyNode.next;
        }
        if (sortedLeft != null)
            dummyNode.next = sortedLeft;
        if (sortedRight != null)
            dummyNode.next = sortedRight;
        return result.next;
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}